package views;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.cloudgarden.layout.AnchorConstraint;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import com.cloudgarden.layout.AnchorConstraint;
import com.cloudgarden.layout.AnchorLayout;

import controllers.Crear_Odontologo_Controller;




/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Crear_Odontologo extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JLabel lblNombre;
	private JTextField txtNombre;
	private JButton btnCancelar;
	private JButton btnOk;
	private JTextField txtMatricula;
	private JTextField txtApellido;
	private JLabel lblMatricula;
	private JLabel lblApellido;
	private Actions l= new Actions();
	private JFrame parent;
	private Crear_Odontologo_Controller controller= Crear_Odontologo_Controller.getInstancia();
		
	/**
	* Auto-generated main method to display this JFrame
	*/

	public Crear_Odontologo(JFrame parent) {
		super();
		this.parent= parent;
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			AnchorLayout thisLayout = new AnchorLayout();
			getContentPane().setLayout(thisLayout);
			this.setTitle("Crear Odontologo");
			this.setPreferredSize(new java.awt.Dimension(722, 546));
			{
				lblNombre = new JLabel();
				getContentPane().add(lblNombre, new AnchorConstraint(208, 190, 265, 74, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				lblNombre.setText("Nombre: ");
				lblNombre.setPreferredSize(new java.awt.Dimension(71, 20));
			}
			{
				lblApellido = new JLabel();
				getContentPane().add(lblApellido, new AnchorConstraint(390, 190, 444, 74, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				lblApellido.setText("Apellido: ");
				lblApellido.setPreferredSize(new java.awt.Dimension(71, 19));
			}
			{
				lblMatricula = new JLabel();
				getContentPane().add(lblMatricula, new AnchorConstraint(563, 204, 617, 74, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				lblMatricula.setText("Matricula: ");
				lblMatricula.setPreferredSize(new java.awt.Dimension(80, 19));
			}
			{
				txtNombre = new JTextField();
				getContentPane().add(txtNombre, new AnchorConstraint(197, 728, 276, 304, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				txtNombre.setPreferredSize(new java.awt.Dimension(260, 28));
			}
			{
				txtApellido = new JTextField();
				getContentPane().add(txtApellido, new AnchorConstraint(376, 728, 455, 304, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				txtApellido.setPreferredSize(new java.awt.Dimension(260, 28));
			}
			{
				txtMatricula = new JTextField();
				getContentPane().add(txtMatricula, new AnchorConstraint(549, 728, 629, 304, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				txtMatricula.setPreferredSize(new java.awt.Dimension(260, 28));
			}
			{
				btnOk = new JButton();
				getContentPane().add(btnOk, new AnchorConstraint(856, 743, 955, 591, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				btnOk.setText("Ok");
				btnOk.setPreferredSize(new java.awt.Dimension(93, 35));
				btnOk.addActionListener(l);
			}
			{
				btnCancelar = new JButton();
				getContentPane().add(btnCancelar, new AnchorConstraint(845, 974, 944, 821, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				btnCancelar.setText("Cancelar");
				btnCancelar.setPreferredSize(new java.awt.Dimension(94, 35));
				btnCancelar.addActionListener(l);
			}
			pack();
			this.setSize(722, 546);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public class Actions implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			Object source = e.getSource();
			
			if(source == btnOk)
			{
				boolean validar;
				if (controller.validarNombre(txtNombre.getText()) && controller.validarNombre(txtApellido.getText()) && controller.validarMatricula(txtMatricula.getText()))
				{
					validar= controller.crearOdontologo(txtNombre.getText(), txtApellido.getText(), txtMatricula.getText());
					if(validar)
					{
						parent.setEnabled(true);
						dispose();
					}
				}				
			}
			else if (source == btnCancelar)
			{
				dispose();
				parent.setEnabled(true);
			}
			
		}
		
	}

}